package com.example.kaoqinmanager.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferenceUtil {
    private SharedPreferences mSharedPreferences;
    private static SharedPreferences.Editor editor;
    private static SharePreferenceUtil mPreferenceUtils;

    public SharePreferenceUtil(Context context) {
        mSharedPreferences = context.getSharedPreferences("369sp", Context.MODE_PRIVATE);
        editor = mSharedPreferences.edit();
    }


    public static synchronized SharePreferenceUtil getInstance(Context cxt) {
        if (mPreferenceUtils == null) {
            mPreferenceUtils = new SharePreferenceUtil(cxt);
        }

        return mPreferenceUtils;
    }


    public String getUserName() {
        return mSharedPreferences.getString("username", "");
    }

    public void setUserName(String name) {
        editor.putString("username", name);
        editor.commit();
    }

    public String getUserId() {
        return mSharedPreferences.getString("userId", "");
    }

    public void setUserId(String href) {
        editor.putString("userId", href);
        editor.commit();
    }


    public boolean getIsLogin() {
        return mSharedPreferences.getBoolean("isLogin", false);
    }

    public void setIsLogin(boolean isLogin) {
        editor.putBoolean("isLogin", isLogin);
        editor.commit();
    }


    //是否为第一次打开app，是的话，显示引导页,默认值为true
    public boolean getIsFirstOpenApp() {
        return mSharedPreferences.getBoolean("is_first_open_app", true);
    }

    public void setIsFirstOpenApp(boolean IsFirstOpenApp) {
        editor.putBoolean("is_first_open_app", IsFirstOpenApp);
        editor.commit();
    }


    public String getAddress() {
        return mSharedPreferences.getString("detail_address", "");
    }

    public void setAddress(String detailAddress) {
        editor.putString("detail_address", detailAddress);
        editor.commit();
    }

    //设置高德地图定位信息（经纬度） 如：潍坊市+经度+维度
    public void setLocationMessage(String strLocationMessage) {
        editor.putString("location_message", strLocationMessage);
        editor.commit();
    }

    //获取高德地图定位信息（经纬度）
    public String getLocationMessage() {
        return mSharedPreferences.getString("location_message", "");
    }

    //设置高德地图详细定位信息，如：山东省潍坊市xx街道
    public void setLocationDetailMessage(String strLocationMessage) {
        editor.putString("location_detail_message", strLocationMessage);
        editor.commit();
    }

    //获取高德地图详细定位信息，如：山东省潍坊市xx街道
    public String getLocationDetailMessage() {
        return mSharedPreferences.getString("location_detail_message", "");
    }


    public String getUserPassword() {
        return mSharedPreferences.getString("password", "");
    }

    public void setUserPassword(String password) {
        editor.putString("password", password);
        editor.commit();
    }


    public int getUserRole() {
        return mSharedPreferences.getInt("UserRole", 2);
    }

    public void setUserRole(int userRole) {
        editor.putInt("UserRole", userRole);
        editor.commit();
    }

    public String getNickName() {
        return mSharedPreferences.getString("user_nick_name", "");
    }

    public void setNickName(String userNickName) {
        editor.putString("user_nick_name", userNickName);
        editor.commit();
    }


    //定位相关
    public void setLatitude(String latitude) {
        editor.putString("latitude", latitude);
        editor.commit();
    }

    public String getLatitude() {
        return mSharedPreferences.getString("latitude", "");
    }

    public void setLongtitude(String latitude) {
        editor.putString("longtitude", latitude);
        editor.commit();
    }

    public String getLongtitude() {
        return mSharedPreferences.getString("longtitude", "");
    }


}
